/**
 * @file app_data.c
 * @brief 应用采集文件
 * @author liucx (liucx@fiberhome.com)
 * @version 1.0
 * @date 2020-12-01
 * @copyright Copyright (c) 2020  烽火通信
 ***************************************************************
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version  < th>Author  <th>Description
 * <tr><td>2020-12-01 <td>1.0      <td>liucx   <td>内容
 * </table>
 */
#include "project_config.h"
#if BOARD_PCU_EN
#include "app_data.h"
#include "app_control.h"
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "bsp_rtc.h"
#include "bsp_log.h"
#include "alarm.h"
#include "bsp_iwdg.h"
#include "sys_wdt.h"
#if PCU_APP_LEAKAGE_TASK_EN
TimerHandle_t leakage_timer = NULL;
uint8_t leakage_tick = 0;
#endif
static xSemaphoreHandle g_heart_sem = NULL;
TimerHandle_t  hartTimerId = NULL;
#if PCU_APP_STRONG_V_TASK_EN
/**
 * @brief 强电采集任务
 * @return uint8_t SUCCESS：成功  ERROR：失败
 */
static void app_data_strong_current_task(void *para)
{
    uint8_t dev_type1 = 0;
    uint8_t dev_type2 = 0;
    uint8_t status = 0;
    uint8_t i = 0;
    uint8_t dev_over_voltage = 0;
    uint8_t dev_low_voltage = 0;
    uint8_t light_over_voltage = 0;
    uint8_t light_low_voltage = 0;
    uint8_t main_loop_status = 0;
    uint8_t strong_tick[20] = {0};
    STRONG_CURRENT_TASK_t strong_current_task;
    BRANCH_220V_LOOP_t branch_220V_loop;
    ALTERNATING_STATUS_t alternating_status;
    memset(strong_tick,0,20);
    while(1)
    {
        vTaskDelay(STRONG_CURRENT_TASK_DELAY);
        threadWdt_Feed(ENUM_TASK_STRONG_CURRENT);
        //判断是否主电源掉电
        if(OK != app_control_220v_main_loop_status(&main_loop_status) || main_loop_status)
        {
            vTaskDelay(POWER_DOWN_DEALY);
            continue;
        }
        /* 获取强电阈值参数 */
        if(OK != app_control_strong_current_task_get(&strong_current_task))
        {
            log_e(" app_control_strong_current_task_get fail ");
            continue;
        }

        if(OK != app_control_220v_branch_loop_electricity(&branch_220V_loop))
        {
            log_e(" app_control_220v_branch_loop_electricity fail ");
            if(OK != Alarm_Send(ALARM_POWER2_COLLECT_FAULT,NULL,0,ALARM_ON))
            {
                log_e("ALARM_POWER2_COLLECT_FAULT ALARM_ON send fail \r\n");
            }
            continue;
        }
        else
        {
            if(OK != Alarm_Send(ALARM_POWER2_COLLECT_FAULT,NULL,0,ALARM_OFF))
            {
                log_e("ALARM_POWER2_COLLECT_FAULT ALARM_OFF send fail \r\n");
            }
        }
        if(OK != app_control_dev_type(LIGHT_1_AISLE,&dev_type1))
        {
            continue;
        }
        if(OK != app_control_dev_type(LIGHT_2_AISLE,&dev_type2))
        {
            continue;
        }
        if(branch_220V_loop.voltage > ALTERNATING_HIGH_VOLTAGE)
        {
            dev_over_voltage++;
            if(dev_over_voltage > OVER_VOLTAGE_TIMES)
            {
                dev_over_voltage = 0;
				if(OK != app_control_220v_main_loop_status(&main_loop_status) || main_loop_status)
				{
					vTaskDelay(POWER_DOWN_DEALY);
					continue;
				}
                /* 过压告警 */
                if(OK != Alarm_Send(ALARM_AC_HIGH,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_AC_HIGH ALARM_ON send fail \r\n");
                }
                /* 关闭交流回路 */
                for(i = AISLE_220V_1; i <= AISLE_220V_3 ; i++)
                {
                    if(OK != app_control_switch_set(i,SWITCH_CLOSE))
                    {
                        continue;
                    }
                }
                //关闭交流总开关
                if(OK != app_control_switch_set(AISLE_ALTERNATING_LOOP,SWITCH_CLOSE))
                {
                    continue;
                }
            }
        }
        else if(branch_220V_loop.voltage < ALTERNATING_LOW_VOLTAGE && branch_220V_loop.voltage > ALTERNATING_LOW_VOLTAGE_MIN)
        {
            dev_low_voltage++;
            if(dev_low_voltage > LOW_VOLTAGE_TIMES)
            {
                dev_low_voltage = 0;
                if(OK != app_control_220v_main_loop_status(&main_loop_status) || main_loop_status)
                {
                    vTaskDelay(POWER_DOWN_DEALY);
                    continue;
                }
                /* 欠压告警 */
                if(OK != Alarm_Send(ALARM_AC_LOW,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_AC_LOW ALARM_ON send fail \r\n");
                }
                /* 关闭交流回路 */
                for(i = AISLE_220V_1; i <= AISLE_220V_3 ; i++)
                {
                    if(OK != app_control_switch_set(i,SWITCH_CLOSE))
                    {
                        continue;
                    }
                }
                //关闭交流总开关
                if(OK != app_control_switch_set(AISLE_ALTERNATING_LOOP,SWITCH_CLOSE))
                {
                    continue;
                }
            }
        }
        else
        {
            dev_over_voltage = 0;
            dev_low_voltage = 0;
        }
        if(branch_220V_loop.light_voltage > ALTERNATING_HIGH_VOLTAGE)
        {
            light_over_voltage++;
            if(light_over_voltage > OVER_VOLTAGE_TIMES)
            {
                light_over_voltage = 0;
                if(OK != Alarm_Send(ALARM_SINGET_LAMP_AC_HIGH,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_SINGET_LAMP_AC_HIGH ALARM_ON send fail \r\n");
                }
                for(i = AISLE_220V_4; i <= AISLE_220V_5 ; i++)
                {
                    if(OK != app_control_switch_set(i,SWITCH_CLOSE))
                    {
                        continue;
                    }
                }
            }
        }
        else if(branch_220V_loop.light_voltage < ALTERNATING_LOW_VOLTAGE && branch_220V_loop.light_voltage > ALTERNATING_LOW_VOLTAGE_MIN)
        {
            light_low_voltage++;
            if(light_low_voltage > LOW_VOLTAGE_TIMES)
            {
                light_low_voltage = 0;
                if(OK != Alarm_Send(ALARM_SINGET_LAMP_AC_LOW,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_SINGET_LAMP_AC_LOW ALARM_ON send fail \r\n");
                }
            }
        }
        else
        {
            light_over_voltage = 0;
            light_low_voltage = 0;
        }
        
        /* 220V_1 */
        if(branch_220V_loop.loop_1_current > ALTERNATING_HIGH_CURRENT)
        {
            strong_tick[0]++;
            if(strong_tick[0] > STRONG_TICK_LENGTH)
            {
                strong_tick[0] = 0;
                if(OK != Alarm_Send(ALARM_BRANCH1_CURRENT_HIGH,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_BRANCH1_CURRENT_HIGH ALARM_ON send fail \r\n");
                }
                /* 关闭通道输出 */
                if(OK != app_control_switch_set(AISLE_220V_1,SWITCH_CLOSE))
                {
                    log_e("app_control_switch_set %d SWITCH_CLOSE  fail",AISLE_220V_1);
                    continue;
                }
            }
        }
        else
        {
            if(OK != app_control_dev_type(AISLE_220V_1,&dev_type1))
            {
                continue;
            }
            if(branch_220V_loop.loop_1_current < OPEN_CIRCUIT_VALUES_220)
            {
                if(OK != app_control_switch_get(AISLE_220V_1,&status))
                {
                    log_e("app_control_switch_get %d fail ",AISLE_220V_1);
                    continue;
                }
                if(status)
                {
                    strong_tick[1]++;
                    if(strong_tick[1] > STRONG_TICK_LENGTH)
                    {
                        strong_tick[1] = 0;
                        if(OK != Alarm_Send(ALARM_AC1_BREAK,NULL,0,ALARM_ON))
                        {
                            log_e("ALARM_AC1_BREAK ALARM_ON send fail \r\n");
                        }
                        if(dev_type1 == DEV_FAN)
                        {
                            if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_ON))
                            {
                                log_e("ALARM_FAN_FAULT ALARM_ON send fail \r\n");
                            }
                        }
                        else if(dev_type1 == DEV_HEATER)
                        {
                            if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_ON))
                            {
                                log_e("ALARM_HOT_FAULT ALARM_ON send fail \r\n");
                            }
                        }
                    }
                }
                else
                {
                    strong_tick[1] = 0;             
                }
            }
            else
            {
                strong_tick[0] = 0;
                strong_tick[1] = 0;
                if(OK != Alarm_Send(ALARM_AC1_BREAK,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_AC1_BREAK ALARM_OFF send fail \r\n");
                }
                if(dev_type1 == DEV_FAN)
                {
                    if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_FAN_FAULT ALARM_OFF send fail \r\n");
                    }
                }
                else if(dev_type1 == DEV_HEATER)
                {
                    if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_HOT_FAULT ALARM_OFF send fail \r\n");
                    }
                }
            }
        }


        /* 220V_2 */
        if(branch_220V_loop.loop_2_current > ALTERNATING_HIGH_CURRENT)
        {
            strong_tick[2]++;
            if(strong_tick[2] > STRONG_TICK_LENGTH)
            {
                strong_tick[2] = 0;
                if(OK != Alarm_Send(ALARM_BRANCH2_CURRENT_HIGH,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_BRANCH2_CURRENT_HIGH ALARM_ON send fail \r\n");
                }
                /* 关闭通道输出 */
                if(OK != app_control_switch_set(AISLE_220V_2,SWITCH_CLOSE))
                {
                    log_e("app_control_switch_set %d SWITCH_CLOSE  fail",AISLE_220V_2);
                    continue;
                }
            }
        }
        else
        {
            if(OK != app_control_dev_type(AISLE_220V_2,&dev_type1))
            {
                continue;
            }
            if(branch_220V_loop.loop_2_current < OPEN_CIRCUIT_VALUES_220)
            {
                if(OK != app_control_switch_get(AISLE_220V_2,&status))
                {
                    log_e("app_control_switch_get %d fail ",AISLE_220V_2);
                    continue;
                }
                if(status)
                {
                    strong_tick[3]++;
                    if(strong_tick[3] > STRONG_TICK_LENGTH)
                    {
                        strong_tick[3] = 0;
                        if(OK != Alarm_Send(ALARM_AC2_BREAK,NULL,0,ALARM_ON))
                        {
                            log_e("ALARM_AC2_BREAK ALARM_ON send fail \r\n");
                        }
                        if(dev_type1 == DEV_FAN)
                        {
                            if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_ON))
                            {
                                log_e("ALARM_FAN_FAULT ALARM_ON send fail \r\n");
                            }
                        }
                        else if(dev_type1 == DEV_HEATER)
                        {
                            if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_ON))
                            {
                                log_e("ALARM_HOT_FAULT ALARM_ON send fail \r\n");
                            }
                        }
                    }
                }
                else
                {
                    strong_tick[3] = 0;               
                }
            }
            else
            {
                strong_tick[2] = 0;
                strong_tick[3] = 0;
                if(OK != Alarm_Send(ALARM_AC2_BREAK,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_AC2_BREAK ALARM_OFF send fail \r\n");
                }
                if(dev_type1 == DEV_FAN)
                {
                    if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_FAN_FAULT ALARM_OFF send fail \r\n");
                    }
                }
                else if(dev_type1 == DEV_HEATER)
                {
                    if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_HOT_FAULT ALARM_OFF send fail \r\n");
                    }
                }
            }
        }


        /* 220V_3 */
        if(branch_220V_loop.loop_3_current > ALTERNATING_HIGH_CURRENT)
        {
            strong_tick[4]++;
            if(strong_tick[4] > STRONG_TICK_LENGTH)
            {
                strong_tick[4] = 0;
                if(OK != Alarm_Send(ALARM_BRANCH3_CURRENT_HIGH,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_BRANCH3_CURRENT_HIGH ALARM_ON send fail \r\n");
                }
                /* 关闭通道输出 */
                if(OK != app_control_switch_set(AISLE_220V_3,SWITCH_CLOSE))
                {
                    log_e("app_control_switch_set %d SWITCH_CLOSE  fail",AISLE_220V_3);
                    continue;
                }
            }
        }
        else
        {
            if(OK != app_control_dev_type(AISLE_220V_3,&dev_type1))
            {
                continue;
            }
            if(branch_220V_loop.loop_3_current < OPEN_CIRCUIT_VALUES_220)
            {
                if(OK != app_control_switch_get(AISLE_220V_3,&status))
                {
                    log_e("app_control_switch_get %d fail ",AISLE_220V_3);
                    continue;
                }
                if(status)
                {
                    strong_tick[5]++;
                    if(strong_tick[5] > STRONG_TICK_LENGTH)
                    {
                        strong_tick[5] = 0;
                        if(OK != Alarm_Send(ALARM_AC3_BREAK,NULL,0,ALARM_ON))
                        {
                            log_e("ALARM_AC3_BREAK ALARM_ON send fail \r\n");
                        }
                        if(dev_type1 == DEV_FAN)
                        {
                            if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_ON))
                            {
                                log_e("ALARM_FAN_FAULT ALARM_ON send fail \r\n");
                            }
                        }
                        else if(dev_type1 == DEV_HEATER)
                        {
                            if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_ON))
                            {
                                log_e("ALARM_HOT_FAULT ALARM_ON send fail \r\n");
                            }
                        }
                    }
                }
                else
                {
                    strong_tick[5] = 0;
                }
            }
            else
            {
                strong_tick[4] = 0;
                strong_tick[5] = 0;
                if(OK != Alarm_Send(ALARM_AC3_BREAK,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_AC3_BREAK ALARM_OFF send fail \r\n");
                }
                if(dev_type1 == DEV_FAN)
                {
                    if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_FAN_FAULT ALARM_OFF send fail \r\n");
                    }
                }
                else if(dev_type1 == DEV_HEATER)
                {
                    if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_HOT_FAULT ALARM_OFF send fail \r\n");
                    }
                }
            }
        }
        /* 单灯1 */
        if(OK != app_control_alternating_status(&alternating_status))
        {
            continue;
        }
        if(OK != app_control_dev_type(LIGHT_1_AISLE,&dev_type1))
        {
            continue;
        }
        if(dev_type1 == DEV_LED )
        {
            if(OK != app_control_switch_get(LIGHT_1_AISLE,&status))
            {
                log_e("app_control_switch_get %d fail ",LIGHT_1_AISLE);
                continue;
            }
            if(branch_220V_loop.loop_4_current > LED_OVER_CURRENT)
            {
                strong_tick[6]++;
                if(strong_tick[6] > STRONG_TICK_LENGTH)
                {
                    strong_tick[6] = 0;
                    if(OK != Alarm_Send(ALARM_SINGET_LAMP1_CURRENT_HIGH,NULL,0,ALARM_ON))
                    {
                        log_e("ALARM_SINGET_LAMP1_CURRENT_HIGH ALARM_ON send fail \r\n");
                    }
                    /* 关闭通道输出 */
                    if(OK != app_control_switch_set(LIGHT_1_AISLE,SWITCH_CLOSE))
                    {
                        log_e("app_control_switch_set %d SWITCH_CLOSE  fail",LIGHT_1_AISLE);
                        continue;
                    }
                }
            }
            else if(status)
            {
                strong_tick[6] = 0;
                if(OK != Alarm_Send(ALARM_SINGET_LAMP1_CURRENT_HIGH,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_SINGET_LAMP1_CURRENT_HIGH ALARM_OFF send fail \r\n");
                }
            }

            if(alternating_status.v_Power_DECT4 != status )
            {
                strong_tick[7]++;
                if(strong_tick[7] > STRONG_TICK_LENGTH)
                {
                    strong_tick[7] = 0;
                    if(OK != Alarm_Send(ALARM_SINGET_LAMP1_RELAY_FAULT,NULL,0,ALARM_ON))
                    {
                        log_e("ALARM_SINGET_LAMP1_ADJUST_FAULT ALARM_ON send fail \r\n");
                    }
                }
            }
            else if(alternating_status.v_Power_DECT4 == status)
            {
                strong_tick[7] = 0;
                if(OK != Alarm_Send(ALARM_SINGET_LAMP1_RELAY_FAULT,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_SINGET_LAMP1_ADJUST_FAULT ALARM_OFF send fail \r\n");
                }
            }
        }

        /* 220V_4 */
        if(branch_220V_loop.loop_4_current > ALTERNATING_HIGH_CURRENT)
        {
            strong_tick[8]++;
            if(strong_tick[8] > STRONG_TICK_LENGTH)
            {
                strong_tick[8] = 0;
                if(OK != Alarm_Send(ALARM_BRANCH4_CURRENT_HIGH,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_BRANCH4_CURRENT_HIGH ALARM_ON send fail \r\n");
                }
                /* 关闭通道输出 */
                if(OK != app_control_switch_set(AISLE_220V_4,SWITCH_CLOSE))
                {
                    log_e("app_control_switch_set %d SWITCH_CLOSE  fail",AISLE_220V_4);
                    continue;
                }
            }
        }
        else
        {
            if(branch_220V_loop.loop_4_current < OPEN_CIRCUIT_VALUES_220)
            {
                if(OK != app_control_switch_get(AISLE_220V_4,&status))
                {
                    log_e("app_control_switch_get %d fail ",AISLE_220V_4);
                    continue;
                }
                if(status)
                {
                    strong_tick[9]++;
                    if(strong_tick[9] > STRONG_TICK_LENGTH)
                    {
                        strong_tick[9] = 0;
                        if(OK != Alarm_Send(ALARM_AC4_BREAK,NULL,0,ALARM_ON))
                        {
                            log_e("ALARM_AC4_BREAK ALARM_ON send fail \r\n");
                        }
                        if(dev_type1 == DEV_FAN)
                        {
                            if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_ON))
                            {
                                log_e("ALARM_FAN_FAULT ALARM_ON send fail \r\n");
                            }
                        }
                        else if(dev_type1 == DEV_HEATER)
                        {
                            if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_ON))
                            {
                                log_e("ALARM_HOT_FAULT ALARM_ON send fail \r\n");
                            }
                        }
                        else if(dev_type1 == DEV_LED)
                        {
                            if(OK != Alarm_Send(ALARM_SINGET_LAMP1_BREAK,NULL,0,ALARM_ON))
                            {
                                log_e("ALARM_SINGET_LAMP1_BREAK ALARM_ON send fail \r\n");
                            }
                        }
                    }
                }
                else
                {
                    strong_tick[9] = 0;
                }
            }
            else
            {
                strong_tick[8] = 0;
                strong_tick[9] = 0;
                if(OK != Alarm_Send(ALARM_AC4_BREAK,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_AC4_BREAK ALARM_OFF send fail \r\n");
                }
                if(dev_type1 == DEV_FAN)
                {
                    if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_FAN_FAULT ALARM_OFF send fail \r\n");
                    }
                }
                else if(dev_type1 == DEV_HEATER)
                {
                    if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_HOT_FAULT ALARM_OFF send fail \r\n");
                    }
                }
                else if(dev_type1 == DEV_LED)
                {
                    if(OK != Alarm_Send(ALARM_SINGET_LAMP1_BREAK,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_SINGET_LAMP1_BREAK ALARM_OFF send fail \r\n");
                    }
                }
            }
        }
        
        /* 单灯2 */
        if(OK != app_control_dev_type(LIGHT_2_AISLE,&dev_type1))
        {
            continue;
        }
        if(dev_type1 == DEV_LED)
        {
            if(OK != app_control_switch_get(LIGHT_2_AISLE,&status))
            {
                log_e("app_control_switch_get %d fail ",LIGHT_2_AISLE);
                continue;
            }
            if(branch_220V_loop.loop_5_current > LED_OVER_CURRENT)
            {
                strong_tick[10]++;
                if(strong_tick[10] > STRONG_TICK_LENGTH)
                {
                    strong_tick[10] = 0;
                    if(OK != Alarm_Send(ALARM_SINGET_LAMP2_CURRENT_HIGH,NULL,0,ALARM_ON))
                    {
                        log_e("ALARM_SINGET_LAMP2_CURRENT_HIGH ALARM_ON send fail \r\n");
                    }
                    /* 关闭通道输出 */
                    if(OK != app_control_switch_set(LIGHT_2_AISLE,SWITCH_CLOSE))
                    {
                        log_e("app_control_switch_set %d SWITCH_CLOSE  fail",LIGHT_2_AISLE);
                        continue;
                    }
                }
            }
            else if(status)
            {
                strong_tick[10] = 0;
                if(OK != Alarm_Send(ALARM_SINGET_LAMP2_CURRENT_HIGH,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_SINGET_LAMP2_CURRENT_HIGH ALARM_OFF send fail \r\n");
                }
            }

            if(alternating_status.v_Power_DECT5 != status )
            {
                strong_tick[11]++;
                if(strong_tick[11] > STRONG_TICK_LENGTH)
                {
                    strong_tick[11] = 0;
                    if(OK != Alarm_Send(ALARM_SINGET_LAMP2_RELAY_FAULT,NULL,0,ALARM_ON))
                    {
                        log_e("ALARM_SINGET_LAMP2_ADJUST_FAULT ALARM_ON send fail \r\n");
                    }
                }
            }
            else if(alternating_status.v_Power_DECT2 == status)
            {
                strong_tick[11] = 0;
                if(OK != Alarm_Send(ALARM_SINGET_LAMP2_RELAY_FAULT,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_SINGET_LAMP2_ADJUST_FAULT ALARM_OFF send fail \r\n");
                }
            }
        }
        
        /* 220V_5 */
        if(branch_220V_loop.loop_5_current > ALTERNATING_HIGH_CURRENT)
        {
            strong_tick[12]++;
            if(strong_tick[12] > STRONG_TICK_LENGTH)
            {
                strong_tick[12] = 0;
                if(OK != Alarm_Send(ALARM_BRANCH5_CURRENT_HIGH,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_BRANCH5_CURRENT_HIGH ALARM_ON send fail \r\n");
                }
                /* 关闭通道输出 */
                if(OK != app_control_switch_set(AISLE_220V_5,SWITCH_CLOSE))
                {
                    log_e("app_control_switch_set %d SWITCH_CLOSE  fail",AISLE_220V_5);
                    continue;
                }
            }
        }
        else
        {
            if(branch_220V_loop.loop_5_current < OPEN_CIRCUIT_VALUES_220)
            {
                if(OK != app_control_switch_get(AISLE_220V_5,&status))
                {
                    log_e("app_control_switch_get %d fail ",AISLE_220V_5);
                    continue;
                }
                if(status)
                {
                    strong_tick[13]++;
                    if(strong_tick[13] > STRONG_TICK_LENGTH)
                    {
                        strong_tick[13] = 0;
                        if(OK != Alarm_Send(ALARM_AC5_BREAK,NULL,0,ALARM_ON))
                        {
                            log_e("ALARM_AC5_BREAK ALARM_ON send fail \r\n");
                        }
                        if(dev_type1 == DEV_FAN)
                        {
                            if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_ON))
                            {
                                log_e("ALARM_FAN_FAULT ALARM_ON send fail \r\n");
                            }
                        }
                        else if(dev_type1 == DEV_HEATER)
                        {
                            if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_ON))
                            {
                                log_e("ALARM_HOT_FAULT ALARM_ON send fail \r\n");
                            }
                        }
                        else if(dev_type1 == DEV_LED)
                        {
                            if(OK != Alarm_Send(ALARM_SINGET_LAMP2_BREAK,NULL,0,ALARM_ON))
                            {
                                log_e("ALARM_SINGET_LAMP2_BREAK ALARM_ON send fail \r\n");
                            }
                        }
                    }
                }
                else
                {
                    strong_tick[13] = 0;
                }
            }
            else
            {
                strong_tick[12] = 0;
                strong_tick[13] = 0;
                if(OK != Alarm_Send(ALARM_AC5_BREAK,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_AC5_BREAK ALARM_OFF send fail \r\n");
                }
                if(dev_type1 == DEV_FAN)
                {
                    if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_FAN_FAULT ALARM_OFF send fail \r\n");
                    }
                }
                else if(dev_type1 == DEV_HEATER)
                {
                    if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_HOT_FAULT ALARM_OFF send fail \r\n");
                    }
                }
                else if(dev_type1 == DEV_LED)
                {
                    if(OK != Alarm_Send(ALARM_SINGET_LAMP2_BREAK,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_SINGET_LAMP2_BREAK ALARM_OFF send fail \r\n");
                    }
                }
            }
        }
    }
}
#endif

#if PCU_APP_WEAK_V_TASK_EN
/**
 * @brief 弱电采集任务
 * @return uint8_t SUCCESS：成功  ERROR：失败
 */
static void app_data_weak_current_task(void *para)
{
    uint8_t dev_type = 0;
    uint8_t status = 0;
    uint8_t i = 0;
    uint8_t main_loop_status = 0;
	uint8_t weak_tick[20] = {0};
    WEAK_CURRENT_TASK_t weak_current_task;
    DIRECT_ELECTRICITY_t direct_electricity;
	memset(weak_tick,0,20);
    while(1)
    {
        vTaskDelay(WEAK_CURRENT_TASK_DELAY);
        threadWdt_Feed(ENUM_TASK_WEAK_CURRENT);
        //判断是否主电源掉电
        if(OK != app_control_220v_main_loop_status(&main_loop_status) || main_loop_status)
        {
            vTaskDelay(POWER_DOWN_DEALY);
            continue;
        }
        /* 获取弱电参数 */
        if(OK != app_control_direct_electricity( &direct_electricity ))
        {
            log_e("app_control_direct_electricity fail ");
            continue;
        }
        /* 获取弱电阈值参数 */
        if(OK != app_control_weak_current_task_get( &weak_current_task ))
        {
            log_e("app_control_weak_current_task_get fail ");
            continue;
        }
        
        /* 24V */
        if(direct_electricity.I_24V > DIRECT_HIGH_CURRENT)
        {
			weak_tick[0]++;
			if(weak_tick[0] > WEAK_TICK_LENGTH)
			{
				weak_tick[0] = 0;
				if(OK != Alarm_Send(ALARM_DC24V_CURRENT_HIGH,NULL,0,ALARM_ON))
				{
					log_e("ALARM_DC24V_CURRENT_HIGH ALARM_ON send fail \r\n");
				}
				/* 关闭通道输出 */
				if(OK != app_control_switch_set(AISLE_24V,SWITCH_CLOSE))
				{
					log_e("app_control_switch_set %d SWITCH_CLOSE  fail",i);
					continue;
				}
			}
            
        }
        else
        {
            if(OK != app_control_dev_type(AISLE_24V,&dev_type))
            {
                continue;
            }
            if(direct_electricity.I_24V < OPEN_CIRCUIT_VALUES)
            {
				if(OK != app_control_switch_get(AISLE_24V,&status))
				{
					log_e("app_control_switch_get %d fail ",AISLE_24V);
					continue;
				}
				if(status)
				{
					weak_tick[1]++;
					if(weak_tick[1] > WEAK_TICK_LENGTH)
					{
						weak_tick[1] = 0;
						if(OK != Alarm_Send(ALARM_DC24_BREAK,NULL,0,ALARM_ON))
						{
							log_e("ALARM_DC24_BREAK ALARM_ON send fail \r\n");
						}

						if(dev_type == DEV_FAN)
						{
							if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_ON))
							{
								log_e("ALARM_FAN_FAULT ALARM_ON send fail \r\n");
							}
						}
						else if(dev_type == DEV_HEATER)
						{
							if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_ON))
							{
								log_e("ALARM_HOT_FAULT ALARM_ON send fail \r\n");
							}
						}
					}
					
				}
				else
				{
					weak_tick[1] = 0;
				}
            }
            else
            {
				weak_tick[0] = 0;
				weak_tick[1] = 0;
                if(OK != Alarm_Send(ALARM_DC24_BREAK,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_DC24_BREAK ALARM_OFF send fail \r\n");
                }
                if(dev_type == DEV_FAN)
                {
                    if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_FAN_FAULT ALARM_OFF send fail \r\n");
                    }
                }
                else if(dev_type == DEV_HEATER)
                {
                    if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_HOT_FAULT ALARM_OFF send fail \r\n");
                    }
                }
            }
        }
        
        /* 12V_1 */
        if(direct_electricity.I_12V_1 > DIRECT_HIGH_CURRENT)
        {
			weak_tick[2]++;
			if(weak_tick[2] > WEAK_TICK_LENGTH)
			{
				weak_tick[2] = 0;
				if(OK != Alarm_Send(ALARM_DC12V_BRANCH1_CURRENT_HIGH,NULL,0,ALARM_ON))
				{
					log_e("ALARM_DC12V_BRANCH1_CURRENT_HIGH ALARM_ON send fail \r\n");
				}
				/* 关闭通道输出 */
				if(OK != app_control_switch_set(AISLE_12V_1,SWITCH_CLOSE))
				{
					log_e("app_control_switch_set %d SWITCH_CLOSE  fail",i);
					continue;
				}
			}
        }
        else
        {
            if(OK != app_control_dev_type(AISLE_12V_1,&dev_type))
            {
                continue;
            }
            if(direct_electricity.I_12V_1 < OPEN_CIRCUIT_VALUES)
            {
                if(OK != app_control_switch_get(AISLE_12V_1,&status))
                {
                    log_e("app_control_switch_get %d fail ",AISLE_12V_1);
                    continue;
                }
                if(status)
                {
					weak_tick[3]++;
					if(weak_tick[3] > WEAK_TICK_LENGTH)
					{
						weak_tick[3] = 0;
						if(OK != Alarm_Send(ALARM_DC12_BRANCH1_BREAK,NULL,0,ALARM_ON))
						{
							log_e("ALARM_DC12_BRANCH1_BREAK ALARM_ON send fail \r\n");
						}

						if(dev_type == DEV_FAN)
						{
							if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_ON))
							{
								log_e("ALARM_FAN_FAULT ALARM_ON send fail \r\n");
							}
						}
						else if(dev_type == DEV_HEATER)
						{
							if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_ON))
							{
								log_e("ALARM_HOT_FAULT ALARM_ON send fail \r\n");
							}
						}
					}
                }
				else
				{
					weak_tick[3] = 0;
				}
            }
            else
            {
				weak_tick[2] = 0;
				weak_tick[3] = 0;
                if(OK != Alarm_Send(ALARM_DC12_BRANCH1_BREAK,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_DC12_BRANCH1_BREAK ALARM_OFF send fail \r\n");
                }

                if(dev_type == DEV_FAN)
                {
                    if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_FAN_FAULT ALARM_OFF send fail \r\n");
                    }
                }
                else if(dev_type == DEV_HEATER)
                {
                    if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_HOT_FAULT ALARM_OFF send fail \r\n");
                    }
                }
            }
        }

        /* 12V_2 */
        if(direct_electricity.I_12V_2 > DIRECT_HIGH_CURRENT)
        {
			weak_tick[4]++;
			if(weak_tick[4] > WEAK_TICK_LENGTH)
			{
				weak_tick[4] = 0;
				if(OK != Alarm_Send(ALARM_DC12V_BRANCH2_CURRENT_HIGH,NULL,0,ALARM_ON))
				{
					log_e("ALARM_DC12V_BRANCH2_CURRENT_HIGH ALARM_ON send fail \r\n");
				}
				/* 关闭通道输出 */
				if(OK != app_control_switch_set(AISLE_12V_2,SWITCH_CLOSE))
				{
					log_e("app_control_switch_set %d SWITCH_CLOSE  fail",i);
					continue;
				}
			}
        }
        else
        {
            if(OK != app_control_dev_type(AISLE_12V_2,&dev_type))
            {
                continue;
            }
            if(direct_electricity.I_12V_2 < OPEN_CIRCUIT_VALUES)
            {
                if(OK != app_control_switch_get(AISLE_12V_2,&status))
                {
                    log_e("app_control_switch_get %d fail ",AISLE_12V_2);
                    continue;
                }
                if(status)
                {
					weak_tick[5]++;
					if(weak_tick[5] > WEAK_TICK_LENGTH)
					{
						weak_tick[5] = 0;
						if(OK != Alarm_Send(ALARM_DC12_BRANCH2_BREAK,NULL,0,ALARM_ON))
						{
							log_e("ALARM_DC12_BRANCH2_BREAK ALARM_ON send fail \r\n");
						}

						if(dev_type == DEV_FAN)
						{
							if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_ON))
							{
								log_e("ALARM_FAN_FAULT ALARM_ON send fail \r\n");
							}
						}
						else if(dev_type == DEV_HEATER)
						{
							if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_ON))
							{
								log_e("ALARM_HOT_FAULT ALARM_ON send fail \r\n");
							}
						}
					}
                }
				else
				{
					weak_tick[5] = 0;
				}
            }
            else
            {
				weak_tick[4] = 0;
				weak_tick[5] = 0;
                if(OK != Alarm_Send(ALARM_DC12_BRANCH2_BREAK,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_DC12_BRANCH2_BREAK ALARM_OFF send fail \r\n");
                }

                if(dev_type == DEV_FAN)
                {
                    if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_FAN_FAULT ALARM_OFF send fail \r\n");
                    }
                }
                else if(dev_type == DEV_HEATER)
                {
                    if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_HOT_FAULT ALARM_OFF send fail \r\n");
                    }
                }
            }
        }

        /* 12V_3 */
        if(direct_electricity.I_12V_3 > DIRECT_HIGH_CURRENT)
        {
			weak_tick[6]++;
			if(weak_tick[6] > WEAK_TICK_LENGTH)
			{
				weak_tick[6] = 0;
				if(OK != Alarm_Send(ALARM_DC12V_BRANCH3_CURRENT_HIGH,NULL,0,ALARM_ON))
				{
					log_e("ALARM_DC12V_BRANCH3_CURRENT_HIGH ALARM_ON send fail \r\n");
				}
				/* 关闭通道输出 */
				if(OK != app_control_switch_set(AISLE_12V_3,SWITCH_CLOSE))
				{
					log_e("app_control_switch_set %d SWITCH_CLOSE  fail",i);
					continue;
				}
			}
        }
        else
        {
            if(OK != app_control_dev_type(AISLE_12V_3,&dev_type))
            {
                continue;
            }
            if(direct_electricity.I_12V_3 < OPEN_CIRCUIT_VALUES)
            {
                if(OK != app_control_switch_get(AISLE_12V_3,&status))
                {
                    log_e("app_control_switch_get %d fail ",AISLE_12V_3);
                    continue;
                }
                if(status)
                {
					weak_tick[7]++;
					if(weak_tick[7] > WEAK_TICK_LENGTH)
					{
						weak_tick[7] = 0;
						if(OK != Alarm_Send(ALARM_DC12_BRANCH3_BREAK,NULL,0,ALARM_ON))
						{
							log_e("ALARM_DC12_BRANCH3_BREAK ALARM_ON send fail \r\n");
						}
						if(dev_type == DEV_FAN)
						{
							if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_ON))
							{
								log_e("ALARM_FAN_FAULT ALARM_ON send fail \r\n");
							}
						}
						else if(dev_type == DEV_HEATER)
						{
							if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_ON))
							{
								log_e("ALARM_HOT_FAULT ALARM_ON send fail \r\n");
							}
						}
					}
                    else
                    {
                        weak_tick[7] = 0;
                    }
                }
            }
            else
            {
                weak_tick[6] = 0;
                weak_tick[7] = 0;
                if(OK != Alarm_Send(ALARM_DC12_BRANCH3_BREAK,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_DC12_BRANCH3_BREAK ALARM_OFF send fail \r\n");
                }
                if(dev_type == DEV_FAN)
                {
                    if(OK != Alarm_Send(ALARM_FAN_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_FAN_FAULT ALARM_OFF send fail \r\n");
                    }
                }
                else if(dev_type == DEV_HEATER)
                {
                    if(OK != Alarm_Send(ALARM_HOT_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_e("ALARM_HOT_FAULT ALARM_OFF send fail \r\n");
                    }
                }
            }
        }

        /* 12V_485_1 */
        if(direct_electricity.I_485_VCC1 > DIRECT_HIGH_CURRENT)
        {
            weak_tick[8]++;
			if(weak_tick[8] > WEAK_TICK_LENGTH)
			{
				weak_tick[8] = 0;
                if(OK != Alarm_Send(ALARM_UP_DC12V_CURRENT_HIGH,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_UP_DC12V_CURRENT_HIGH ALARM_ON send fail \r\n");
                }
                /* 关闭通道输出 */
                if(OK != app_control_switch_set(AISLE_12V_485_1,SWITCH_CLOSE))
                {
                    log_e("app_control_switch_set %d SWITCH_CLOSE  fail",i);
                    continue;
                }
            }
        }
        else
        {
            if(direct_electricity.I_485_VCC1 < OPEN_CIRCUIT_VALUES)
            {
                if(OK != app_control_switch_get(AISLE_12V_485_1,&status))
                {
                    log_e("app_control_switch_get %d fail ",AISLE_12V_485_1);
                    continue;
                }
                if(status)
                {
                    weak_tick[9]++;
					if(weak_tick[9] > WEAK_TICK_LENGTH)
					{
						weak_tick[9] = 0;
                        if(OK != Alarm_Send(ALARM_UP_DC12V_BREAK,NULL,0,ALARM_ON))
                        {
                            log_e("ALARM_UP_DC12V_BREAK ALARM_ON send fail \r\n");
                        }
                    }
                }
                else
				{
					weak_tick[9] = 0;
				}
            }
            else
            {
                weak_tick[8] = 0;
                weak_tick[9] = 0;
                if(OK != Alarm_Send(ALARM_UP_DC12V_BREAK,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_UP_DC12V_BREAK ALARM_OFF send fail \r\n");
                }
            }
        }        

        /* 12V_485_2 */
        if(direct_electricity.I_485_VCC2 > DIRECT_HIGH_CURRENT)
        {
            weak_tick[10]++;
			if(weak_tick[10] > WEAK_TICK_LENGTH)
			{
				weak_tick[10] = 0;
                if(OK != Alarm_Send(ALARM_EXTEND_DC12V_CURRENT_HIGH,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_EXTEND_DC12V_CURRENT_HIGH ALARM_ON send fail \r\n");
                }
                /* 关闭通道输出 */
                if(OK != app_control_switch_set(AISLE_12V_485_2,SWITCH_CLOSE))
                {
                    log_e("app_control_switch_set %d SWITCH_CLOSE  fail",i);
                    continue;
                }
            }
        }
        else
        {
            if(direct_electricity.I_485_VCC2 < OPEN_CIRCUIT_VALUES)
            {
                if(OK != app_control_switch_get(AISLE_12V_485_2,&status))
                {
                    log_e("app_control_switch_get %d fail ",AISLE_12V_485_2);
                    continue;
                }
                if(status)
                {
                    weak_tick[11]++;
					if(weak_tick[11] > WEAK_TICK_LENGTH)
					{
						weak_tick[11] = 0;
                        if(OK != Alarm_Send(ALARM_EXTEND_DC12V_BREAK,NULL,0,ALARM_ON))
                        {
                            log_e("ALARM_EXTEND_DC12V_BREAK ALARM_ON send fail \r\n");
                        }
                    }
                }
                else
                {
                    weak_tick[11] = 0;
                }
            }
            else
            {
                weak_tick[10] = 0;
                weak_tick[11] = 0;
                if(OK != Alarm_Send(ALARM_EXTEND_DC12V_BREAK,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_EXTEND_DC12V_BREAK ALARM_OFF send fail \r\n");
                }
            }
        }      
    
        if(direct_electricity.V_12V > DIRECT_12V_HIGH_VOLTAGE)
        {
			if(OK != app_control_220v_main_loop_status(&main_loop_status) || main_loop_status)
			{
				vTaskDelay(POWER_DOWN_DEALY);
				continue;
			}
            weak_tick[12]++;
            if(weak_tick[12] > WEAK_TICK_LENGTH)
            {
                weak_tick[12] = 0;	
                /* 过压告警 */
                if(OK != Alarm_Send(ALARM_DC12V_HIGH,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_DC12V_HIGH ALARM_ON send fail \r\n");
                }
                /* 关闭12V */
                for(i = AISLE_12V_1; i <= AISLE_12V_485_2 ; i++)
                {
                    if(OK != app_control_switch_set(i,SWITCH_CLOSE))
                    {
                        continue;
                    }
                }
            }
        }
        else if(direct_electricity.V_12V < DIRECT_12V_LOW_VOLTAGE)
        {
			if(OK != app_control_220v_main_loop_status(&main_loop_status) || main_loop_status)
			{
				vTaskDelay(POWER_DOWN_DEALY);
				continue;
			}
            weak_tick[13]++;
            if(weak_tick[13] > WEAK_TICK_LENGTH)
            {
                weak_tick[13] = 0;
                /* 欠压告警 */
                if(OK != Alarm_Send(ALARM_DC12V_LOW,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_DC12V_LOW ALARM_ON send fail \r\n");
                }
                /* 关闭12V */
                for(i = AISLE_12V_1; i <= AISLE_12V_485_2 ; i++)
                {
                    if(OK != app_control_switch_set(i,SWITCH_CLOSE))
                    {
                        log_e("app_control_switch_set fail \r\n");
                        continue;
                    }
                }
            }
        }
        else
        {
            weak_tick[12] = 0;
            weak_tick[13] = 0;
        }

        if(OK != app_control_switch_get(AISLE_24V,&status))
        {
            log_e("app_control_switch_get %d fail ",AISLE_24V);
            continue;
        }
        if(direct_electricity.V_24V > DIRECT_24V_HIGH_VOLTAGE)
        {
			if(OK != app_control_220v_main_loop_status(&main_loop_status) || main_loop_status)
			{
				vTaskDelay(POWER_DOWN_DEALY);
				continue;
			}
            weak_tick[14]++;
            if(weak_tick[14] > WEAK_TICK_LENGTH)
            {
                weak_tick[14] = 0;	
                /* 过压告警 */
                if(OK != Alarm_Send(ALARM_DC24V_HIGH,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_DC24V_HIGH ALARM_ON send fail \r\n");
                }
                /* 关闭24V */
                if(OK != app_control_switch_set(AISLE_24V,SWITCH_CLOSE))
                {
                    continue;
                }
            }
        }
        else if(direct_electricity.V_24V < DIRECT_24V_LOW_VOLTAGE && status)
        {
			if(OK != app_control_220v_main_loop_status(&main_loop_status) || main_loop_status)
			{
				vTaskDelay(POWER_DOWN_DEALY);
				continue;
			}
            weak_tick[15]++;
            if(weak_tick[15] > WEAK_TICK_LENGTH)
            {
                weak_tick[15] = 0;
                /* 欠压告警 */
                if(OK != Alarm_Send(ALARM_DC24V_LOW,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_DC24V_LOW ALARM_ON send fail \r\n");
                }
                /* 关闭24V */
                if(OK != app_control_switch_set(AISLE_24V,SWITCH_CLOSE))
                {
                    log_e("app_control_switch_set fail \r\n");
                    continue;
                }
            }
        }
        else
        {
            weak_tick[14] = 0;
            weak_tick[15] = 0;
        }
    }
}
#endif

#if PCU_APP_LEAKAGE_TASK_EN
/**
 * @brief 漏电动作定时器回调
 * @return uint8_t SUCCESS：成功  ERROR：失败
 */
static void app_data_leakageTimer_timeout(TimerHandle_t xTimer)
{
    /* 开启设备回路 */
    app_control_switch_set(AISLE_DIRECT_LOOP,SWITCH_OPEN);
    app_control_switch_set(AISLE_ALTERNATING_LOOP,SWITCH_OPEN);
    leakage_tick++;
}



/**
 * @brief 漏电采集任务
 * @return uint8_t SUCCESS：成功  ERROR：失败
 */
static void app_data_leakage_task(void *para)
{
    LEAKAGE_TASK_t leakage_task_values;
    uint32_t leakage_communicate = 0;
    uint32_t leakage_light = 0;
    uint8_t power_lock_alarm = 0;
    uint8_t status_direct = 0;
    uint8_t status_alter = 0;
    while (1)
    {
        vTaskDelay(1000);
        threadWdt_Feed(ENUM_TASK_LEAKAGE);
        /* 获取漏电电流阈值及漏电控制位 */
        if(OK != app_control_leakage_task_get(&leakage_task_values))
        {
            log_e(" app_control_leakage_task_get fail ");
            continue;
        }

        /* 采集漏电电流 */
        if(OK != app_control_leakage(&leakage_communicate,&leakage_light))
        {
            if(OK != Alarm_Send(ALARM_POWER1_COLLECT_FAULT,NULL,0,ALARM_ON))
            {
                log_e("ALARM_POWER1_COLLECT_FAULT ALARM_ON send fail \r\n");
            }
            continue;
        }
        else
        {
            if(OK != Alarm_Send(ALARM_POWER1_COLLECT_FAULT,NULL,0,ALARM_OFF))
            {
                log_e("ALARM_POWER1_COLLECT_FAULT ALARM_OFF send fail \r\n");
            }
        }

        //单灯回路漏电
        if(leakage_light > leakage_task_values.leakage_values)
        {
            if(OK != Alarm_Send(ALARM_SINGET_LAMP_LOOP_LEAKAGE,NULL,0,ALARM_ON))
            {
                log_e("ALARM_SINGET_LAMP_LOOP_LEAKAGE ALARM_ON send fail \r\n");
            }
            /* 执行告警动作 */
            if(OK != app_control_switch_set(LIGHT_1_AISLE,SWITCH_CLOSE))
            {
                log_e("app_control_switch_set fail \r\n");
            }
            if(OK != app_control_switch_set(LIGHT_2_AISLE,SWITCH_CLOSE))
            {
                log_e("app_control_switch_set fail \r\n");
            }
        }
        else
        {
            /* 上报告警解除 */
            if(OK != Alarm_Send(ALARM_SINGET_LAMP_LOOP_LEAKAGE,NULL,0,ALARM_OFF))
            {
                log_e("ALARM_SINGET_LAMP_LOOP_LEAKAGE ALARM_OFF send fail \r\n");
            }
        }
        
        if(leakage_task_values.leakage_enable == LEAKAGE_NO_ACTION)
        {
            /* 不进行漏电保护 */
            log_i(" LEAKAGE_NO_ACTION ");
            continue;
        }
        
        /* 判断是否产生锁死告警 */
        if(OK != Alarm_Assign_State_Get(ALARM_POWER_LOCK,&power_lock_alarm))
        {
            log_e("ALARM_POWER_LOCK get fail ");
            continue;
        }

        if(power_lock_alarm)
        {
            log_i("ALARM_POWER_LOCK is ON ");
            continue;
        }

        if(OK != app_control_switch_get(AISLE_ALTERNATING_LOOP,&status_alter))
        {
            log_e("app_control_switch_get fail ");
            continue;
        }
        if(OK != app_control_switch_get(AISLE_DIRECT_LOOP,&status_direct))
        {
            log_e("app_control_switch_get fail ");
            continue;
        }
        if(!status_direct && !status_alter)
        {
            continue;
        }

        if (leakage_communicate <= leakage_task_values.leakage_values )
        {
            if(leakage_task_values.leakage_enable == LEAKAGE_ALARM_REPORT || (leakage_task_values.leakage_enable == LEAKAGE_ACTION && leakage_tick != 0))
            {
                /* 上报告警解除 */
                if(OK != Alarm_Send(ALARM_LEAKAGE_HIGH,NULL,0,ALARM_OFF))
                {
                    log_e("ALARM_LEAKAGE_HIGH ALARM_OFF send fail \r\n");
                }
                /* 关闭定时器 */
                if (NULL != leakage_timer)
                {
                    xTimerDelete(leakage_timer, 0);
                    leakage_timer = NULL;
                    leakage_tick = 0;
                }                
            }
            continue;
        }

        /* 上报告警产生 */
        if(OK != Alarm_Send(ALARM_LEAKAGE_HIGH,NULL,0,ALARM_ON))
        {
            log_e("ALARM_LEAKAGE_HIGH ALARM_ON send fail \r\n");
        }

        if (leakage_task_values.leakage_enable == LEAKAGE_ACTION)
        {
            app_control_switch_set(AISLE_DIRECT_LOOP,SWITCH_CLOSE);
            app_control_switch_set(AISLE_ALTERNATING_LOOP,SWITCH_CLOSE);
            /* 判断是否产生锁死告警 */
            if (leakage_tick >= leakage_task_values.leakage_frequency)
            {
                /* 产生锁死告警 */
                if(OK != Alarm_Send(ALARM_POWER_LOCK,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_POWER_LOCK ALARM_ON send fail \r\n");
                }
                /* 关闭定时器 */
                if (NULL != leakage_timer)
                {
                    xTimerDelete(leakage_timer, 0);
                    leakage_timer = NULL;
                    leakage_tick = 0;
                }
                continue;
            }
            /* 开启定时器 */
            if (NULL == leakage_timer && leakage_task_values.leakage_times != 0)
            {
                leakage_timer = xTimerCreate("leakage_timer", leakage_task_values.leakage_times * 1000 * portTICK_RATE_MS, pdFALSE, NULL, app_data_leakageTimer_timeout);
                leakage_tick = 0;
            }
            if (xTimerIsTimerActive(leakage_timer) == pdFALSE)
            {
                xTimerStart(leakage_timer, 0);
            }
        }
    }
}
#endif

#if PCU_APP_TEM_TASK_EN
/**
 * @brief 温度采集任务
 * @return uint8_t SUCCESS：成功  ERROR：失败
 */
static void app_data_temperature_task(void *para)
{
    uint8_t i = 0;
    float temperature = 0;
    TEMPERATURE_TASK_t temperature_task_values;
    while (1)
    {
        vTaskDelay(TEMPERATURE_TASK_DEALY);
        threadWdt_Feed(ENUM_TASK_TEMPERATURE);
        /* 获取温度值 */
        if(OK != app_control_temperature(&temperature))
        {
            continue;
        }
        /* 获取相关阈值参数 */
        if(OK != app_control_temperature_task_get(&temperature_task_values))
        {
            continue;
        }
        if(temperature <= temperature_task_values.high_temperature && temperature >= temperature_task_values.low_temperature)
        {
            /* 上报温度告警恢复 */
            if(OK != Alarm_Send(ALARM_HIGH_TEMP,NULL,0,ALARM_OFF))
            {
                log_e("ALARM_HIGH_TEMP ALARM_OFF send fail \r\n");
            }
            if(OK != Alarm_Send(ALARM_LOW_TEMP,NULL,0,ALARM_OFF))
            {
                log_e("ALARM_LOW_TEMP ALARM_OFF send fail \r\n");
            }
        }
        else
        {
            if(temperature > temperature_task_values.high_temperature)
            {
                /* 上报高温告警 */
                if(OK != Alarm_Send(ALARM_HIGH_TEMP,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_HIGH_TEMP ALARM_ON send fail \r\n");
                }
            }
            else if(temperature < temperature_task_values.low_temperature)
            {
                /* 上报低温告警 */
                if(OK != Alarm_Send(ALARM_LOW_TEMP,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_LOW_TEMP ALARM_ON send fail \r\n");
                }
            }
            if(temperature_task_values.temperature_enable)
            {
                /* 关闭支路 */
                for(i = AISLE_24V; i <= AISLE_220V_5 ; i++)
                {
                    if(OK != app_control_switch_set(i,SWITCH_CLOSE))
                    {
                        continue;
                    }
                }
                continue;
            }
        }
        if(temperature >= temperature_task_values.fan_temperature)
        {
            /* 开启风扇 */
            if(OK != app_control_fan_heater(DEV_FAN,SWITCH_OPEN))
            {
                log_e("app_control_fan_heater DEV_FAN SWITCH_OPEN fail \r\n");
                continue;
            }
            /* 关闭加热棒 */
            if(OK != app_control_fan_heater(DEV_HEATER,SWITCH_CLOSE))
            {
                log_e("app_control_fan_heater DEV_HEATER SWITCH_CLOSE fail \r\n");
                continue;
            }
        }
        else if(temperature >= temperature_task_values.fan_temperature - TEMPERATURE_CONTROL_LIMIT)
        {
            /* 关闭加热棒 */
            if(OK != app_control_fan_heater(DEV_HEATER,SWITCH_CLOSE))
            {
                log_e("app_control_fan_heater DEV_HEATER SWITCH_CLOSE fail \r\n");
                continue;
            }
        }
        else if(temperature >= temperature_task_values.heater_temperature + TEMPERATURE_CONTROL_LIMIT)
        {
            /* 关闭风扇 */
            if(OK != app_control_fan_heater(DEV_FAN,SWITCH_CLOSE))
            {
                log_e("app_control_fan_heater DEV_FAN SWITCH_CLOSE fail \r\n");
                continue;
            }
            /* 关闭加热棒 */
            if(OK != app_control_fan_heater(DEV_HEATER,SWITCH_CLOSE))
            {
                log_e("app_control_fan_heater DEV_HEATER SWITCH_CLOSE fail \r\n");
                continue;
            }
        }
        else if(temperature > temperature_task_values.heater_temperature )
        {
            /* 关闭风扇 */
            if(OK != app_control_fan_heater(DEV_FAN,SWITCH_CLOSE))
            {
                log_e("app_control_fan_heater DEV_FAN SWITCH_CLOSE fail \r\n");
                continue;
            }
        }
        else
        {
            /* 关闭风扇 */
            if(OK != app_control_fan_heater(DEV_FAN,SWITCH_CLOSE))
            {
                log_e("app_control_fan_heater DEV_FAN SWITCH_CLOSE fail \r\n");
                continue;
            }
            /* 开启加热棒 */
            if(OK != app_control_fan_heater(DEV_HEATER,SWITCH_OPEN))
            {
                log_e("app_control_fan_heater DEV_HEATER SWITCH_OPEN fail \r\n");
                continue;
            }
        }
    }
}
#endif

#if PCU_APP_LCD_TASK_EN
/**
* @brief 显示屏任务
 * @return uint8_t SUCCESS：成功  ERROR：失败
 */
void app_data_lcd_screen_task(void *para)
{
    UPGRADE_VALUES_t upgrade_values;
    while (1)
    {
        vTaskDelay(OLED_TASK_DELAY);
        threadWdt_Feed(ENUM_TASK_LCD);
        //upgrade check
        if(OK != app_control_upgrade_values_get(&upgrade_values))
        {
            continue;
        }
        if(upgrade_values.upgrade_status == UPGRADE_STATUS_ON)
        {
            continue;
        }
        app_control_oled_show_port(OLED_SHOW_PORT);
        vTaskDelay(OLED_TASK_DELAY);
        threadWdt_Feed(ENUM_TASK_LCD);
        app_control_oled_show_port(OLED_SHOW_ALARM);
    }
}
#endif

#if PCU_APP_TILT_TASK_EN
/**
 * @brief 倾斜角度采集任务
 * @return uint8_t SUCCESS：成功  ERROR：失败
 */
void app_data_tilt_task(void *para)
{
    uint8_t tilt_times = 0;
	uint8_t tilt_alarm_times_x = 0;
	uint8_t tilt_alarm_times_y = 0;
	uint8_t tilt_alarm_times_z = 0;
    float tilt_x = 0;
    float tilt_y = 0;
    float tilt_z = 0;
    TILT_TASK_t tilt_task;
    int32_t error_code = OK;
    UPGRADE_VALUES_t upgrade_values;
    while (1)
    {
        vTaskDelay(TILT_TASK_DELAY);
        threadWdt_Feed(ENUM_TASK_TILT);
        //upgrade check
        if(OK != app_control_upgrade_values_get(&upgrade_values))
        {
            continue;
        }
        if(upgrade_values.upgrade_status == UPGRADE_STATUS_ON)
        {
            continue;
        }
        error_code = app_control_tilt(&tilt_x,&tilt_y,&tilt_z);
        if(OK != error_code)
        {
            tilt_times++;
            if(tilt_times >= 3)
            {
                tilt_times = 0;
                log_e(" app_control_tilt fail\r\n");
                /* 产生倾斜获取失败告警 */
                if(OK != Alarm_Send(ALARM_LEAN_COLLECT_FAULT,NULL,0,ALARM_ON))
                {
                    log_e("ALARM_LEAN_COLLECT_FAULT ALARM_ON send fail \r\n");
                }
                continue;
				
            }
			continue;
        }
        else
        {
            tilt_times = 0;
            /* 产生倾斜获取失败告警恢复 */
            if(OK != Alarm_Send(ALARM_LEAN_COLLECT_FAULT,NULL,0,ALARM_OFF))
            {
                log_e("ALARM_LEAN_COLLECT_FAULT ALARM_ON send fail \r\n");
            }
        }
        
        if(OK != app_control_tilt_task_get(&tilt_task))
        {
            continue;
        }
        
        if(tilt_task.tilt_x - tilt_x > (float)tilt_task.tilt || tilt_x - tilt_task.tilt_x > (float)tilt_task.tilt)
        {
			tilt_alarm_times_x++;
            if(tilt_alarm_times_x >= 3)
            {
                tilt_alarm_times_x = 0;
				/* 产生倾斜告警 */
				if(OK != Alarm_Send(ALARM_LEAN,NULL,0,ALARM_ON))
				{
					log_e("ALARM_LEAN ALARM_ON send fail \r\n");
				}
			}
            continue;
        }
		else
		{
			tilt_alarm_times_x = 0;
		}
		
        if(tilt_task.tilt_y - tilt_y > (float)tilt_task.tilt || tilt_y - tilt_task.tilt_y > (float)tilt_task.tilt)
        {
			tilt_alarm_times_y++;
            if(tilt_alarm_times_y >= 3)
            {
                tilt_alarm_times_y = 0;
				/* 产生倾斜告警 */
				if(OK != Alarm_Send(ALARM_LEAN,NULL,0,ALARM_ON))
				{
					log_e("ALARM_LEAN ALARM_ON send fail \r\n");
				}
			}
            continue;
        }
		else
		{
			tilt_alarm_times_y = 0;
		}
		
        if(tilt_task.tilt_z - tilt_z > (float)tilt_task.tilt || tilt_z - tilt_task.tilt_z > (float)tilt_task.tilt)
        {
			tilt_alarm_times_z++;
            if(tilt_alarm_times_z >= 3)
            {
                tilt_alarm_times_z = 0;
				/* 产生倾斜告警 */
				if(OK != Alarm_Send(ALARM_LEAN,NULL,0,ALARM_ON))
				{
					log_e("ALARM_LEAN ALARM_ON send fail \r\n");
				}
			}
            continue;
        }
		else
		{
			tilt_alarm_times_z = 0;
		}
		
		tilt_alarm_times_x = 0;
		tilt_alarm_times_y = 0;
		tilt_alarm_times_z = 0;
		
        if(OK != Alarm_Send(ALARM_LEAN,NULL,0,ALARM_OFF))
        {
            log_e("ALARM_LEAN ALARM_OFF send fail \r\n");
        }
    }
    
}
#endif

#if PCU_APP_HEART_TASK_EN
/**
 * @brief 心跳周期上报任务
 * @return uint8_t SUCCESS：成功  ERROR：失败
 */
void app_data_heart_task(void *para)
{
    while(1)
    {
        threadWdt_Feed(ENUM_TASK_HEART);
		if(xSemaphoreTake(g_heart_sem, 2000) != pdTRUE)
		{
        	continue;
    	}

        log_i("app_data_heart_task \r\n");
        /* 心跳包上报 */
        int32_t ret = app_control_heart_package_report();
        if(OK != ret)
        {
            // if (ret == -2)
            // {
            //     log_e("wiz reset.... \r\n");
            //     wiz_reset();
            //     wiz_config( NULL );
            // }
            log_e("heart_package send fail(%d) \r\n", ret);
            if(OK != Alarm_Send(ALARM_MSC_NET_FAULT,NULL,0,ALARM_ON))
            {
                log_e("ALARM_MSC_UP_FAULT ALARM_ON send fail \r\n");
            }
        }
        else
        {
            if(OK != Alarm_Send(ALARM_MSC_NET_FAULT,NULL,0,ALARM_OFF))
            {
                log_e("ALARM_MSC_UP_FAULT ALARM_OFF send fail \r\n");
            }
        }
    }
}
#endif

#if PCU_APP_DI_TASK_EN
/**
 * @brief DI设备状态采集任务
 * @return uint8_t SUCCESS：成功  ERROR：失败
 */
void app_data_DI_task(void *para)
{
    uint8_t DI1_status = 0;
    uint8_t DI1_old_status = 2;
    uint8_t DI2_status = 0;
    uint8_t DI2_old_status = 2;
    uint8_t DI1_dev_default = 0;
    uint8_t DI2_dev_default = 0;
    uint8_t dev_type = 0;
    uint8_t main_loop_status = 0;
    uint8_t main_loop_old_status = 2;
    while(1)
    {  
        vTaskDelay(1000);
        threadWdt_Feed(ENUM_TASK_DI);
        if(OK != app_control_220v_main_loop_status(&main_loop_status))
        {
            continue;
        }
        if(main_loop_status && (main_loop_old_status != main_loop_status))
        {
            /* 主电源掉电告警 */
            if(OK != Alarm_Send(ALARM_MASTER_POWER_LOST,NULL,0,ALARM_ON))
            {
                log_i("ALARM_MASTER_POWER_LOST ALARM_ON send fail \r\n");
            }
            /* 执行掉电动作 */
            if(OK != app_control_main_loop_power_down())
            {
                continue;
            }
            if(app_control_energy_update())
            {
                continue;
            }
            if(OK != app_control_save())
            {
                continue;
            }
        }
        else if (!main_loop_status && (main_loop_old_status != main_loop_status))
        {
            /* 主电源掉电告警恢复 */
            if(OK != Alarm_Send(ALARM_MASTER_POWER_LOST,NULL,0,ALARM_OFF))
            {
                log_i("ALARM_MASTER_POWER_LOST ALARM_ON send fail \r\n");
            }
        }
        main_loop_old_status = main_loop_status;
        /* 获取DIDO设备初始状态 */
        if(OK != app_control_DI(&DI1_status,&DI2_status))
        {
            continue;
        }
        /* 获取DIDO口状态 */
        if(OK != app_control_DI_dev_status(&DI1_dev_default,&DI2_dev_default))
        {
            continue;
        }
        if(OK != app_control_dev_type(AISLE_DI1,&dev_type))
        {
            continue;
        }
        switch (dev_type) 
        {
            case DEV_AIR_SWITCH:
                if(DI1_status != DI1_dev_default && (DI1_old_status != DI1_status))
                {
                    /* 空开告警产生 */
                    if(OK != Alarm_Send(ALARM_AIR_SWITCH_LOST,NULL,0,ALARM_ON))
                    {
                        log_i("ALARM_AIR_SWITCH_LOST ALARM_ON send fail \r\n");
                    }
                }
                else if(DI1_status == DI1_dev_default && (DI1_old_status != DI1_status))
                {
                    /* 空开告警恢复 */
                    if(OK != Alarm_Send(ALARM_AIR_SWITCH_LOST,NULL,0,ALARM_OFF))
                    {
                        log_i("ALARM_AIR_SWITCH_LOST ALARM_OFF send fail \r\n");
                    }
                }
                break;
            case DEV_LIGHTNING_PROTECTOR:
                if(DI1_status != DI1_dev_default && (DI1_old_status != DI1_status))
                {
                    /* 防雷告警产生 */
                    if(OK != Alarm_Send(ALARM_LIGHTING_ARRESTER_FAULT,NULL,0,ALARM_ON))
                    {
                        log_i("ALARM_LIGHTING_ARRESTER_FAULT ALARM_ON send fail \r\n");
                    }
                }
                else if(DI1_status == DI1_dev_default && (DI1_old_status != DI1_status))
                {
                    /* 防雷告警恢复 */
                    if(OK != Alarm_Send(ALARM_LIGHTING_ARRESTER_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_i("ALARM_LIGHTING_ARRESTER_FAULT ALARM_OFF send fail \r\n");
                    }
                }
                break;
            default:
                break;
        }
        DI1_old_status = DI1_status;
        if(OK != app_control_dev_type(AISLE_DI2,&dev_type))
        {
            continue;
        }
        switch (dev_type) 
        {
            case DEV_AIR_SWITCH:
                if(DI2_status != DI2_dev_default && (DI2_old_status != DI2_status))
                {
                    /* 空开告警产生 */
                    if(OK != Alarm_Send(ALARM_AIR_SWITCH_LOST,NULL,0,ALARM_ON))
                    {
                        log_i("ALARM_AIR_SWITCH_LOST ALARM_ON send fail \r\n");
                    }
                }
                else if(DI2_status == DI2_dev_default && (DI2_old_status != DI2_status))
                {
                    /* 空开告警恢复 */
                    if(OK != Alarm_Send(ALARM_AIR_SWITCH_LOST,NULL,0,ALARM_OFF))
                    {
                        log_i("ALARM_AIR_SWITCH_LOST ALARM_OFF send fail \r\n");
                    }
                }
                break;
            case DEV_LIGHTNING_PROTECTOR:
                if(DI2_status != DI2_dev_default && (DI2_old_status != DI2_status))
                {
                    /* 防雷告警产生 */
                    if(OK != Alarm_Send(ALARM_LIGHTING_ARRESTER_FAULT,NULL,0,ALARM_ON))
                    {
                        log_i("ALARM_LIGHTING_ARRESTER_FAULT ALARM_ON send fail \r\n");
                    }
                }
                else if(DI2_status == DI2_dev_default && (DI2_old_status != DI2_status))
                {
                    /* 防雷告警恢复 */
                    if(OK != Alarm_Send(ALARM_LIGHTING_ARRESTER_FAULT,NULL,0,ALARM_OFF))
                    {
                        log_i("ALARM_LIGHTING_ARRESTER_FAULT ALARM_OFF send fail \r\n");
                    }
                }
                break;
            default:
                break;
        }
        DI2_old_status = DI2_status;
    }
    
}
#endif

#if PCU_APP_PLAN_TASK_EN
/**
 * @brief 计划执行任务
 * @return uint8_t SUCCESS：成功  ERROR：失败
 */
void app_data_plan_task(void *para)
{
    uint8_t i = 0;
    PLAN_VALUES_t plan_values;
    rtc_time_t tm;
    uint32_t clock_sys = 0;
    while(1)
    {
        vTaskDelay(PLAN_TASK_DELAY);
        threadWdt_Feed(ENUM_TASK_PLAN);
        if(BSP_SUCCESS != RtcGet(&tm))
        {
            log_e(" get time fail \r\n");
            continue;
        }
        clock_sys = tm.tm_hour*3600 + tm.tm_min*60 + tm.tm_sec;
        for(i = 0 ; i < LIGHT_PLAN_MAX_NUM + AMBIENT_PLAN_MAX_NUM ; i++)
        {
            if(OK != app_control_plan_sel(i,&plan_values))
            {
                log_e(" get plan fail \r\n");
                continue;
            }
            if(plan_values.plan_type == PLAN_TYPE_NULL || plan_values.work_time != clock_sys)
            {
                continue;
            }
            else if(plan_values.plan_type == PLAN_TYPE_LIGHT)
            {
                if(plan_values.light_num == 1)
                {
                    log_i("PLAN_TYPE_LIGHT 1 ");
                    if(OK != app_control_single_light_set(plan_values.light_values,LIGHT_NO_ACTION))
                    {
                        log_e(" light1 control fail \r\n");
                        continue;
                    }
                }
                else if(plan_values.light_num == 2)
                {
                    log_i("PLAN_TYPE_LIGHT 2 ");
                    if(OK != app_control_single_light_set(LIGHT_NO_ACTION,plan_values.light_values))
                    {
                        log_e(" light2 control fail \r\n");
                        continue;
                    }
                }
                else if(plan_values.light_num == BOTH_LIGHT_NUM)
                {
                    log_i("PLAN_TYPE_LIGHT ALL ON ");
                    if(OK != app_control_single_light_set(plan_values.light_values,plan_values.light_values))
                    {
                        log_e(" light1_2 control fail \r\n");
                        continue;
                    }																		
                }									
                else
                {
                    log_e(" light_num fault \r\n");
                }
            }
            else if(plan_values.plan_type == PLAN_TYPE_AMBIENT)
            {
                log_i("PLAN_TYPE_AMBIENT  ");
                if(OK != app_control_ambient_set(plan_values.ambient_type))
                {
                    log_e(" ambient control fail \r\n");
                    continue;
                }
            }
            else
            {
                log_e(" plan type fault \r\n");
            }
        }
    }
}
#endif

/**
* @brief 心跳定时器
* @param xTimer            定时器句柄
* @return uint8_t OK：成功  ERROR_COM：失败
*/
void heart_beat(xTimerHandle xTimer )
{
    xSemaphoreGive(g_heart_sem);
}

/**
 * @brief app_data_heart_init
 * @return uint8_t OK：成功  ERROR_COM：失败
 */
int32_t app_data_heart_init( void )
{
    uint16_t heart_len = 0;
    if(OK!= app_control_heart_get(&heart_len) || heart_len == 0)
    {
        return ERROR_COM;
    }
    hartTimerId = xTimerCreate("heart_Timer",pdMS_TO_TICKS(heart_len*1000),pdTRUE,NULL,heart_beat);
    if(NULL == hartTimerId)
    {
        return ERROR_COM;
    }
    xTimerStart(hartTimerId,0);
    return OK;
}

/**
 * @brief app_data_heart_set
 * @return uint8_t OK：成功  ERROR_COM：失败
 */
int32_t app_data_heart_set( uint16_t heart_beat_lenth )
{
    if(NULL != hartTimerId)
    {
		if(xTimerIsTimerActive(hartTimerId) == pdTRUE)
		{
			xTimerStop(hartTimerId,0);	
		}
        xTimerDelete(hartTimerId,0);
        hartTimerId = xTimerCreate("heart_Timer",pdMS_TO_TICKS(heart_beat_lenth*1000),pdTRUE,NULL,heart_beat);
		xTimerStart(hartTimerId,0);
        return OK;
    }
    return ERROR_COM;
}


/**
 * @brief 数据采集模块初始化
 * @return uint8_t SUCCESS：成功  ERROR：失败
 */
int32_t app_data_init(void)
{
    g_heart_sem = xSemaphoreCreateBinary();
	if (NULL == g_heart_sem) 
	{
		log_e("create g_heart_sem fail !\r\n");
		return ERROR_COM;		
	}
    #if PCU_APP_STRONG_V_TASK_EN
    if(pdTRUE != xTaskCreate( app_data_strong_current_task, (const char*)"strong_current", 256, NULL, 12, NULL))
    {
        log_i("app_data_strong_current_task fail \r\n");
    }
    #endif

    #if PCU_APP_WEAK_V_TASK_EN
    if(pdTRUE != xTaskCreate( app_data_weak_current_task, (const char*)"weak_current", 256, NULL, 12, NULL))
    {
        log_i("app_data_weak_current_task fail \r\n");
    }
    #endif

    #if PCU_APP_LEAKAGE_TASK_EN
    if(pdTRUE != xTaskCreate(app_data_leakage_task, (const char*)"leakage", 196, NULL, 12, NULL))
    {
        log_i("app_data_leakage_task fail \r\n");
    }
    #endif

    #if PCU_APP_TEM_TASK_EN
    if(pdTRUE != xTaskCreate( app_data_temperature_task, (const char*)"temperature", 128, NULL, 12, NULL))
    {
        log_i("app_data_temperature_task fail \r\n");
    }
    #endif

    #if PCU_APP_LCD_TASK_EN
    if(pdTRUE != xTaskCreate( app_data_lcd_screen_task, (const char*)"lcd_screen", 300, NULL, 13, NULL))
    {
        log_i("app_data_lcd_screen_task fail \r\n");
    }
    #endif

    #if PCU_APP_TILT_TASK_EN
    if(pdTRUE != xTaskCreate( app_data_tilt_task, (const char*)"tilt", 284, NULL, 13, NULL))
    {
        log_i("app_data_tilt_task fail \r\n");
    }
    #endif

    #if PCU_APP_HEART_TASK_EN
    if(pdTRUE != xTaskCreate( app_data_heart_task, (const char*)"heart", 512, NULL,12, NULL))
    {
        log_i("app_data_heart_task fail \r\n");
    }
    #endif

    #if PCU_APP_DI_TASK_EN
    if(pdTRUE != xTaskCreate( app_data_DI_task, (const char*)"DI", 256, NULL, 12, NULL))
    {
        log_i("app_data_DI_task fail \r\n");
    }
    #endif

    #if PCU_APP_PLAN_TASK_EN
    if(pdTRUE != xTaskCreate( app_data_plan_task, (const char*)"plan", 256, NULL, 12, NULL))
    {
        log_i("app_data_plan_task fail \r\n");
    }
    #endif
    if(app_data_heart_init() != OK)
    {
        log_e(" app_data_heart_init fail !\r\n");
		return ERROR_COM;	
    }
    return SUCCESS;
}

#endif /* BOARD_PCU_EN */
